package com.personal.gateway.custom.customEnum.flinkCommandEnum;

import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOption;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.ConfigurationTypeEnumInterface;
import lombok.Getter;

import javax.annotation.Nonnull;

/**
 * @author BigHead
 * @date 2022/1/7 14:50
 * @description FlinkTargetEnum
 */
@Getter
public enum FlinkTargetEnum implements ConfigurationTypeEnumInterface {

    /**
     * 远端部署
     */
    REMOTE(FlinkExecutionEnum.RUN, "remote"),
    /**
     * 本地部署
     */
    LOCAL(FlinkExecutionEnum.RUN, "local"),
    /**
     * YARN集群 单job部署
     */
    YARN_PER_JOB(FlinkExecutionEnum.RUN, "yarn-per-job"),
    /**
     * YARN集群 SESSION模式
     */
    YARN_SESSION(FlinkExecutionEnum.RUN, "yarn-session"),
    /**
     * K8s集群 SESSION模式
     */
    KUBERNETES_SESSION(FlinkExecutionEnum.RUN, "kubernetes-session"),
    /**
     * YARN集群 application资源申请模式
     */
    YARN_APPLICATION(FlinkExecutionEnum.RUN_APPLICATION, "yarn-application"),
    /**
     * K8s集群 application资源申请模式
     */
    KUBERNETES_APPLICATION(FlinkExecutionEnum.RUN_APPLICATION, "kubernetes-application");

    public final static Class<Enum<? extends ConfigurationTypeEnumInterface>> TARGET_TYPE_CLASS = (Class<Enum<? extends ConfigurationTypeEnumInterface>>) (Class<?>) FlinkTargetEnum.class;
    private final FlinkExecutionEnum flinkExecutionEnum;
    private final String executionTargetString;

    FlinkTargetEnum(FlinkExecutionEnum flinkExecutionEnum, String executionTargetString) {
        this.flinkExecutionEnum = flinkExecutionEnum;
        this.executionTargetString = executionTargetString;
    }

    @Override
    public String getShowValue() {
        return name();
    }

    @Override
    public String getSelectValue() {
        return this.executionTargetString;
    }

    @Override
    public boolean checkExist(@Nonnull String... values) {
        if (values.length == 1) {
            return executionTargetString.equals(values[0]);
        }
        return false;
    }

    @Override
    public boolean checkExist(ConfigurationOption<?, ?> configurationOption, @Nonnull String... values) {
        if (values.length != 1) {
            return false;
        }
        if (null == configurationOption.getConfigurationType().getValue()){
            return false;
        }
        FlinkExecutionEnum configurationTypeEnumInterface = (FlinkExecutionEnum) configurationOption.getConfigurationType().getValue();
        return flinkExecutionEnum.equals(configurationTypeEnumInterface) && executionTargetString.equals(values[0]);
    }

    @Override
    public boolean checkExampleValue(ConfigurationOption<?, ?> configurationOption) {
        if (null != configurationOption.getConfigurationType().getValue()) {
            FlinkExecutionEnum configurationTypeEnumInterface = (FlinkExecutionEnum) configurationOption.getConfigurationType().getValue();
            return flinkExecutionEnum.equals(configurationTypeEnumInterface);
        }
        return false;
    }
}
